package com.zto.sch.invoke;

import com.zto.sch.dao.CardDao;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @program: javatest
 * @description:
 * @author: sch
 * @create: 2020-09-16 21:57
 **/
//@Component
public class MyFactoryBean implements FactoryBean, InvocationHandler {
    private Class clazz;

    public MyFactoryBean(Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("myinvoke2...");
        return null;
    }

    @Override
    public Object getObject() throws Exception {
        Class<?>[] interfaces = new Class[]{clazz};
        CardDao cardDao = (CardDao) Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, this);
        return cardDao;
    }

    @Override
    public Class<?> getObjectType() {
        return CardDao.class;
    }
}
